package com.lepu.app.main.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.application.MyApplication;
import com.app.config.AppConfig;
import com.app.utils.AppEnterTongJi;
import com.app.utils.Const;
import com.app.utils.DateUtil;
import com.app.utils.LoginUtil;
import com.app.utils.MyStoreUtil;
import com.app.utils.ObserverConst;
import com.app.utils.SdLocal;
import com.app.utils.Setting;
import com.core.lib.application.BaseFragment;
import com.core.lib.core.ApiClient;
import com.core.lib.core.AsyncRequest;
import com.core.lib.core.BitmapManager;
import com.core.lib.utils.Observer;
import com.core.lib.utils.ObserverManager;
import com.core.lib.utils.main.AppManager;
import com.core.lib.utils.main.UIHelper;
import com.core.lib.utils.main.UmengHelper;
import com.core.lib.utils.main.UtilityBase;
import com.core.lib.widget.CircularImageView;
import com.eyzhs.app.R;
import com.lepu.app.fun.market.IntegralAnimaActivity;
import com.lepu.app.fun.my.CollectKnowledgeActivity;
import com.lepu.app.fun.my.MessageAllActivity;
import com.lepu.app.fun.my.MyFenSiActivity;
import com.lepu.app.fun.my.MyPubContentActivity;
import com.lepu.app.fun.my.MyScoreInfoActivity;
import com.lepu.app.fun.my.MyShareYaoQingCodeActivity;
import com.lepu.app.fun.my.SettingActivity;
import com.lepu.app.fun.my.bean.BeanCollectKnowledge;
import com.lepu.app.fun.my.bean.BeanMessage;
import com.lepu.app.fun.my.bean.BeanMessageCount;
import com.lepu.app.main.activity.MainTabActivity;
import com.lepu.app.main.permission.PermissionUtil;
import com.lepu.app.main.permission.callback.PermissionResultCallBack;
import com.lepu.app.usercenter.FeedBackMainActivity;
import com.lepu.app.usercenter.UserInfoActivity;
import com.lepu.app.usercenter.bean.LoginInfo;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewRightButtonListener;

public class MainTabFragmentMy extends BaseFragment implements
        OnTopbarNewRightButtonListener, AsyncRequest, Observer {

    private static final String REQUEST_MY_SCORE = "request_my_score";
    private static final String REQUEST_SIGN_IN = "request_sign_in";
    private static final String REQUEST_MSG = "request_msg";
    private static final String REQUEST_MSG_SYSTEM = "request_msg_system";

    public static final int BOARD = 2;

    private static MainTabFragmentMy mFragmentInstance = null;

    private View mMainView = null;
    private boolean mInitDataSuccess = false;// 是否加载完数据
    private int mTotalScore = 0;

    private TextView mContentTextView; // 内容
    private TextView mCollectTextView; // 收藏
    private TextView mFollowTextView; // 关注
    private TextView mFansTextView; // 粉丝

    private ImageView mSignImage;

    private BeanMessageCount mBeanMsg = new BeanMessageCount(); // 消息bean
    private TextView mMainTopMessageTextView;

    public static MainTabFragmentMy getInstance() {
        return mFragmentInstance;
    }

    @SuppressLint("InflateParams")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mFragmentInstance = this;
        mMainView = LayoutInflater.from(getActivity()).inflate(
                R.layout.main_tab_fragment_my, null, false);
        init();
    }

    @Override
    public void onResume() {
        super.onResume();
        UmengHelper.OnPageStart("25");

        requestAlarm();
        if (mInitDataSuccess) {
            updateLoginState();

            requestMyScore();
        }
    }

    @Override
    public void onPause() {
        super.onPause();

        UmengHelper.OnPageEnd("25");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);

        ViewGroup p = (ViewGroup) mMainView.getParent();
        if (p != null) {
            p.removeAllViewsInLayout();
        }
        return mMainView;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        mInitDataSuccess = false;
        mFragmentInstance = null;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if (isVisibleToUser) {
            requestAlarm();
            requestMyScore();  //每次进入这个界面都需要更新数据
            if (!mInitDataSuccess) {
                mInitDataSuccess = true;
                // 第一次进入页面获取数据
                updateLoginState();
            }

        }
    }

    /*
     * 初始化ui控件，不要初始化数据！！！！
     *
     * 初始化控件，需要用mMainView.findViewById 不能使用findViewById，否则程序会闪退的
     */
    private void init() {
        CustomTopBarNew topbar = (CustomTopBarNew) mMainView
                .findViewById(R.id.topbar);
        topbar.setTopbarTitle("我的");
        topbar.setTopbarLeftLayoutHide();
        // topbar.setRightButton(R.drawable.app_icon_share);
        topbar.setOnTopbarNewRightButtonListener(this);

        RelativeLayout userLayout = (RelativeLayout) mMainView
                .findViewById(R.id.userLayout);
        mContentTextView = (TextView) mMainView
                .findViewById(R.id.contentTextView);
        mCollectTextView = (TextView) mMainView
                .findViewById(R.id.collectTextView);
        mFansTextView = (TextView) mMainView.findViewById(R.id.fansTextView);
        mFollowTextView = (TextView) mMainView.findViewById(R.id.followTextView);

        mSignImage = (ImageView) mMainView.findViewById(R.id.signImageView);

        mMainTopMessageTextView = (TextView) mMainView.findViewById(R.id.messageTextView);

        LinearLayout contentLayout = (LinearLayout) mMainView
                .findViewById(R.id.contentLayout);
        LinearLayout collectLayout = (LinearLayout) mMainView
                .findViewById(R.id.collectLayout);
        LinearLayout fansLayout = (LinearLayout) mMainView
                .findViewById(R.id.fansLayout);
        LinearLayout followLayout = (LinearLayout) mMainView
                .findViewById(R.id.followLayout);

        userLayout.setOnClickListener(mOnClickListener);
        contentLayout.setOnClickListener(mOnClickListener);
        collectLayout.setOnClickListener(mOnClickListener);
        fansLayout.setOnClickListener(mOnClickListener);
        followLayout.setOnClickListener(mOnClickListener);
        mSignImage.setOnClickListener(mOnClickListener);

        RelativeLayout messageLayout = (RelativeLayout) mMainView
                .findViewById(R.id.messageLayout);
        RelativeLayout scoreInfoLayout = (RelativeLayout) mMainView
                .findViewById(R.id.scoreInfoLayout);
        RelativeLayout scoreStoreLayout = (RelativeLayout) mMainView
                .findViewById(R.id.scoreStoreLayout);
        LinearLayout healthyStoreLayout = (LinearLayout) mMainView
                .findViewById(R.id.healthyStoreLayout);
        LinearLayout feedbackLayout = (LinearLayout) mMainView
                .findViewById(R.id.feedbackLayout);
        LinearLayout gradeLayout = (LinearLayout) mMainView
                .findViewById(R.id.gradeLayout);
        LinearLayout settingLayout = (LinearLayout) mMainView
                .findViewById(R.id.settingLayout);
        LinearLayout orderLayout = (LinearLayout) mMainView
                .findViewById(R.id.orderLayout);
        LinearLayout yaoqingCodeLayout = (LinearLayout) mMainView
                .findViewById(R.id.yaoqingCodeLayout);

        messageLayout.setOnClickListener(mOnClickListener);
        scoreInfoLayout.setOnClickListener(mOnClickListener);
        scoreStoreLayout.setOnClickListener(mOnClickListener);
        healthyStoreLayout.setOnClickListener(mOnClickListener);
        feedbackLayout.setOnClickListener(mOnClickListener);
        gradeLayout.setOnClickListener(mOnClickListener);
        settingLayout.setOnClickListener(mOnClickListener);
        orderLayout.setOnClickListener(mOnClickListener);
        yaoqingCodeLayout.setOnClickListener(mOnClickListener);

        ObserverManager.getInstance().addObserver(
                ObserverConst.NOTIFY_MY_FRAGMENT_CHANGE, this);

        // showLogo();
    }

    private void requestMyScore() {
        if (!LoginUtil.checkIsLogin()) {
            //没登陆不显示消息
            mBeanMsg = new BeanMessageCount();
            updateMessage(mBeanMsg);
            return;
        }

        String url = Setting.getMyUserScoreUrl();

        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject params = new JSONObject();
        try {
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());
        } catch (Exception e) {
        }
        map.put("ht", params);
        ApiClient.http_post_main(url, map, null, this, REQUEST_MY_SCORE, true);
    }

    private void requestSignIn() {
        boolean flag = MainTabActivity.jumpLogin(MainTabActivity.getInstance());
        if (flag) {
            return;
        }

        String url = Setting.getMySignInUrl();
        MainTabActivity.getInstance().showProgressDialog();
        // ApiClient.http_get_main(url, this, REQUEST_SIGN_IN);

        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject params = new JSONObject();
        try {
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());
        } catch (Exception e) {
        }
        map.put("ht", params);
        ApiClient.http_post_main(url, map, null, this, REQUEST_SIGN_IN, false, false);
    }

    /**
     * 请求消息
     */
    @SuppressLint("DefaultLocale")
    private void requestAlarm() {
        //请求前初始化
        mBeanMsg = new BeanMessageCount();
        if (!LoginUtil.checkIsLogin()) {
            //没登陆直接请求系统消息
            requestSystemAlarm();
            return;
        }

        String url = Setting.getMassegeCountUrl();

        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject params = new JSONObject();
        try {
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());
        } catch (Exception e) {
        }
        map.put("ht", params);
        String temp = String.format("?key=%d", System.currentTimeMillis());
        ApiClient.http_post_main(url + temp, map, null, this, REQUEST_MSG, true);
    }

    /**
     * 请求系统消息
     */
    private void requestSystemAlarm() {

        String url = Setting.getSystemDataUrl();

        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject params = new JSONObject();
        try {
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());
            params.put("MessageType", 1);
            params.put("AppChannel", UtilityBase.getAppMetedata(getActivity(), "UMENG_CHANNEL")); //渠道来源
            params.put("AppVersion", AppManager.getAppVersionName(getActivity())); //app版本
            long useTimeMill = DateUtil.getNowTimeInMillis() - AppConfig.getConfigLong(getActivity(), Const.CONFIG_APP_USE_TIME, DateUtil.getNowTimeInMillis());
            int useDays = (int) (useTimeMill / DateUtil.DAY_MILLIS);
            params.put("DaysInAPP", useDays); //使用天数
        } catch (Exception e) {
        }
        map.put("ht", params);
        ApiClient.http_post_main(url, map, null, this, REQUEST_MSG_SYSTEM, true);
    }

    public void updateLoginState() {
        CircularImageView accountIconImageView = (CircularImageView) mMainView
                .findViewById(R.id.accountIconImageView);
        TextView usernameTextView = (TextView) mMainView
                .findViewById(R.id.usernameTextView);

        if (MyApplication.getInstance().checkIsLogin()) {

            LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();

            accountIconImageView
                    .setImageResource(R.drawable.app_ic_default_avatar);
            String filePath = SdLocal.getUserPath(getActivity(),
                    loginInfo.UserID);
            String imageUrl = Setting.getImageUrl(loginInfo.Avatar);
            BitmapManager.getInstance().loadBitmap(imageUrl, filePath,
                    accountIconImageView, null, true);

            usernameTextView.setText(loginInfo.NickName);

        } else {
            usernameTextView.setText("未登录");
            accountIconImageView.setImageResource(R.drawable.icon_head_nologin);

            mTotalScore = 0;
            updateScoreText();
            mContentTextView.setText("0");
            mCollectTextView.setText("0");
            mFollowTextView.setText("0");
            mFansTextView.setText("0");

            mSignImage.setVisibility(View.VISIBLE);
        }
    }

    private View.OnClickListener mOnClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.userLayout:

                    boolean loginFlag = MainTabActivity.jumpLogin(MainTabActivity
                            .getInstance());
                    if (!loginFlag) {
                        Intent intent = new Intent(getActivity(),
                                UserInfoActivity.class);
                        MainTabActivity.getInstance().startActivity(intent, true);
                    }
                    break;
                case R.id.contentLayout:

                    boolean flag = MainTabActivity.jumpLogin(MainTabActivity
                            .getInstance());
                    if (!flag) {
                        Intent intent1 = new Intent(getActivity(), MyPubContentActivity.class);
                        MainTabActivity.getInstance().startActivity(intent1, true);
                    }

                    break;
                case R.id.collectLayout:

                    boolean flag2 = MainTabActivity.jumpLogin(MainTabActivity
                            .getInstance());
                    if (!flag2) {
                        Intent intent2 = new Intent(getActivity(),
                                CollectKnowledgeActivity.class);
                        MainTabActivity.getInstance().startActivity(intent2, true);
                    }
                    break;
                case R.id.fansLayout: // 粉丝

                    boolean loginFlagFensi = MainTabActivity
                            .jumpLogin(MainTabActivity.getInstance());
                    if (!loginFlagFensi) {
                        Intent intentFensi = new Intent(getActivity(),
                                MyFenSiActivity.class);
                        intentFensi.putExtra("fensi_guanzhu",
                                MyFenSiActivity.TYPE_FENSI);
                        intentFensi.putExtra("TargetUserID", MyApplication
                                .getInstance().getLoginInfo().UserID);
                        MainTabActivity.getInstance().startActivity(intentFensi,
                                true);
                    }

                    break;
                case R.id.followLayout: // 关注

                    boolean loginFlagGuanzhu = MainTabActivity
                            .jumpLogin(MainTabActivity.getInstance());
                    if (!loginFlagGuanzhu) {
                        Intent intentGuanzhu = new Intent(getActivity(),
                                MyFenSiActivity.class);
                        intentGuanzhu.putExtra("fensi_guanzhu",
                                MyFenSiActivity.TYPE_GUANZHU);
                        intentGuanzhu.putExtra("TargetUserID", MyApplication
                                .getInstance().getLoginInfo().UserID);
                        MainTabActivity.getInstance().startActivity(intentGuanzhu,
                                true);
                    }

                    break;
                case R.id.feedbackLayout:

                    boolean loginFlagFeed = MainTabActivity
                            .jumpLogin(MainTabActivity.getInstance());
                    if (!loginFlagFeed) {
                        Intent intent = new Intent(getActivity(),
                                FeedBackMainActivity.class);
                        MainTabActivity.getInstance().startActivity(intent, true);
                    }

                    break;
                case R.id.gradeLayout:
                    // grade
                    String format = String.format("market://details?id=%s",
                            getActivity().getPackageName());
                    Uri uri = Uri.parse(format);
                    Intent tellotherintent = new Intent(Intent.ACTION_VIEW, uri);
                    try {
                        MainTabActivity.getInstance().startActivity(
                                tellotherintent, true);
                    } catch (ActivityNotFoundException e) {
                        e.printStackTrace();
                    }

                    break;
                case R.id.settingLayout:

                    AppEnterTongJi.clickEvent(60, "");

                    Intent intent4 = new Intent(getActivity(),
                            SettingActivity.class);
                    MainTabActivity.getInstance().startActivity(intent4, true);

                    break;
                case R.id.scoreStoreLayout:  //金币商城

                    AppEnterTongJi.clickEvent(69, "");

                    MyStoreUtil.getInstance().requestMoneyMarket(MainTabActivity.getInstance(), "");

                    break;
                case R.id.signImageView:
                    boolean flagSignOrder = MainTabActivity.jumpLogin(MainTabActivity.getInstance());
                    if (flagSignOrder) {
                        return;
                    }

                    requestSignIn();
                    break;
                case R.id.scoreInfoLayout:  //积分
                    AppEnterTongJi.clickEvent(68, "");

                    boolean flagScoreInfo = MainTabActivity
                            .jumpLogin(MainTabActivity.getInstance());
                    if (!flagScoreInfo) {
                        Intent scoreInfoIntent = new Intent(getActivity(),
                                MyScoreInfoActivity.class);
                        scoreInfoIntent.putExtra("ScoreNumber", mTotalScore);
                        MainTabActivity.getInstance().startActivity(
                                scoreInfoIntent, true);
                    }

                    break;

                case R.id.healthyStoreLayout: // 健康商场

                    AppEnterTongJi.clickEvent(70, "");

                    MyStoreUtil.getInstance().requestAllMarket(MainTabActivity.getInstance(), "");

                    break;
                case R.id.yaoqingCodeLayout:

                    AppEnterTongJi.clickEvent(66, "");

                    if (!MainTabActivity.jumpLogin(MainTabActivity.getInstance())) {
                        // 分享我的邀请码
                        Intent intent = new Intent(getActivity(),
                                MyShareYaoQingCodeActivity.class);
                        MainTabActivity.getInstance().startActivityAnim(intent,
                                R.anim.lib_push_down_up_in,
                                R.anim.lib_push_down_up_out);
                    }
                    break;

                case R.id.messageLayout:

                    Intent intentMessage = new Intent(getActivity(), MessageAllActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("beanMsg", mBeanMsg);
                    intentMessage.putExtras(bundle);
                    MainTabActivity.getInstance().startActivity(intentMessage, true);
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    public void onTopbarRightButtonSelected() {

    }

    private void updateScoreText() {
        TextView scoreValueTextView = (TextView) mMainView
                .findViewById(R.id.scoreValueTextView);
        if (mTotalScore > 0) {
            scoreValueTextView.setText(String.format("%d", mTotalScore));
        } else {
            scoreValueTextView.setText("");
        }
    }

    /**
     * 更新消息
     */
    public void updateMessage(BeanMessageCount beanMessage) {
        if (mMainTopMessageTextView != null) {
            int count = beanMessage.motherCount + beanMessage.phoneCount + beanMessage.writerCount + beanMessage.friendCount + beanMessage.systemCount;// 应从数据库获取，可能。具体再说
            if (count > 0) {
                mMainTopMessageTextView.setText(String.valueOf(count));
                mMainTopMessageTextView.setVisibility(View.VISIBLE);
            } else {
                mMainTopMessageTextView.setVisibility(View.GONE);
            }
        }
    }

    @SuppressLint("InflateParams")
    private void addSignInView(int changeScore) {
        Intent intentAnima = new Intent(getActivity(), IntegralAnimaActivity.class);
        intentAnima.putExtra("integral", String.valueOf(changeScore));
        startActivity(intentAnima);
    }

    @Override
    public void RequestComplete(Object object, Object data) {
        if (object.equals(REQUEST_SIGN_IN)) {
            MainTabActivity.getInstance().hideProgressDialog();

            int changeScore = 0;
            int totalScore = 0;
            try {
                JSONObject jsonObject = new JSONObject((String) data);
                JSONObject obj1 = (JSONObject) jsonObject.get("Result");
                JSONObject dataObject = (JSONObject) obj1.get("DetailInfo");

                changeScore = dataObject.optInt("ChangeCredits");
                totalScore = dataObject.optInt("AvailableCredits");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            if (changeScore > 0) {
                mTotalScore = totalScore;

                updateScoreText();
                addSignInView(changeScore);
            }
        } else if (object.equals(REQUEST_MY_SCORE)) {

            @SuppressWarnings("unused")
            int noUseScore = 0;// 用户总共获得的积分数，不计消耗
            int totalScore = 0;// 可用使用的积分

            int postCount = 0; // 帖子数
            int followCount = 0; // 关注数
            int fansCount = 0; // 粉丝数

            int sign = 0; // 是否签到
            try {
                JSONObject jsonObject = new JSONObject((String) data);
                JSONObject obj1 = (JSONObject) jsonObject.get("Result");
                JSONObject dataObject = (JSONObject) obj1.get("DetailInfo");

                noUseScore = dataObject.optInt("TotalCredits");
                totalScore = dataObject.optInt("AvailableCredits");
                postCount = dataObject.optInt("TopicCount");
                followCount = dataObject.optInt("FollowCount");
                fansCount = dataObject.optInt("FansCount");
                sign = dataObject.optInt("HasSignIn");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            mTotalScore = totalScore;
            updateScoreText();

            mContentTextView.setText(String.valueOf(postCount));
            mCollectTextView.setText(String.valueOf(BeanCollectKnowledge.getAllCollectCount(LoginUtil.getUserId())));
            mFollowTextView.setText(String.valueOf(followCount));
            mFansTextView.setText(String.valueOf(fansCount));

            if (sign == 0) {
                mSignImage.setVisibility(View.VISIBLE);
                final Animation translateAnim = AnimationUtils.loadAnimation(getActivity(), R.anim.sign_translate_anim);
                mSignImage.startAnimation(translateAnim);

            } else if (sign == 1) {
                mSignImage.setVisibility(View.GONE);
            }
        } else if (object.equals(REQUEST_MSG)) {
            mBeanMsg = BeanMessageCount.parseJsonData((String) data);
            updateMessage(mBeanMsg);
            //请求系统消息
            requestSystemAlarm();
        } else if (object.equals(REQUEST_MSG_SYSTEM)) {
            ArrayList<BeanMessage> beanList = BeanMessage.parseJsonSystemData((String) data);
            if (beanList != null) {
                for (BeanMessage item : beanList) {
                    item.Board = 4;
                    item.IsRead = 0;
                    item.LoginUserID = LoginUtil.getUserId();

                    if (!BeanMessage.getMsgIsExist(item.LoginUserID, 4, item.IMID)) {
                        BeanMessage.insertMyMessage(item);
                    }

                }

                int msgCount = BeanMessage.getNewMessageCount(LoginUtil.getUserId(), 4);
                mBeanMsg.systemCount = mBeanMsg.systemCount + msgCount;
                updateMessage(mBeanMsg);
            }
        }
    }

    @Override
    public void RequestError(Object object, int errorId, String data) {
        if (object.equals(REQUEST_SIGN_IN)) {
            MainTabActivity.getInstance().hideProgressDialog();

            // test
            // addSignInView(0);
        } else if (object.equals(REQUEST_MY_SCORE)) {

        } else if (object.equals(REQUEST_MSG)) {
            //及时更新消息状态
            updateMessage(mBeanMsg);
            //请求系统消息
            requestSystemAlarm();
        } else if (object.equals(REQUEST_MSG_SYSTEM)) {
            int msgCount = BeanMessage.getNewMessageCount(LoginUtil.getUserId(), 4);

            mBeanMsg.systemCount = mBeanMsg.systemCount + msgCount;
            //及时更新消息状态
            updateMessage(mBeanMsg);
        }
    }

    @Override
    public void notify(String name, Object sender, Object data) {
        if (name.equals(ObserverConst.NOTIFY_MY_FRAGMENT_CHANGE)) {
            updateLoginState();
        }
    }
}
